package com.jason.cloud.engine.share.driver.grant.service;

import com.jason.cloud.engine.share.driver.grant.bean.GrantBean;
import com.jason.cloud.engine.share.driver.grant.dao.GrantDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class GrantServiceImpl implements GrantService {

    private static final Logger logger = LoggerFactory.getLogger(GrantServiceImpl.class);

    @Resource
    private GrantDao grantDao;

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    public GrantBean queryGrantByRoleId(String id) {
        GrantBean grantBean = null;
        try {
            grantBean = this.grantDao.queryGrantByRoleId(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return grantBean;
    }

    /**
     * 更新授权
     * @param grantBean
     */
    public void updateGrantParam(GrantBean grantBean) {
        try {
            this.grantDao.updateGrantParam(grantBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 保存授权
     * @param grantBean
     */
    public void insertGrant(GrantBean grantBean) {
        try {
            this.grantDao.insertGrant(grantBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 拷贝默认授权
     * @param roleId
     * @return
     */
    public void copyRoleGrantByRoleId(String roleId) {
        try {
            this.grantDao.copyRoleGrantByRoleId(roleId);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }
}
